package com.sxz.sbs.module.client.auth;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sxz.sbs.R;
import com.sxz.sbs.app.GlideApp;
import com.sxz.sbs.base.BaseActivity;
import com.sxz.sbs.constant.IntentConstant;
import com.sxz.sbs.http.retrofit.HttpParamMap;
import com.sxz.sbs.module.client.bean.RealNameBean;
import com.sxz.sbs.module.client.bean.UploadFileBean;
import com.sxz.sbs.module.client.presenter.RealNamePresenter;
import com.sxz.sbs.module.client.view.RealNameView;
import com.sxz.sbs.module.photo.PhotoViewerActivity;
import com.sxz.sbs.module.photo.PhotoViewerBean;
import com.sxz.sbs.widget.CommonTitle;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class RealNameInfoActivity extends BaseActivity<RealNamePresenter> implements RealNameView {


    @BindView(R.id.real_name_name)
    TextView realNameName;
    @BindView(R.id.real_name_number)
    TextView realNameNumber;
    @BindView(R.id.iv_font)
    ImageView ivFont;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    private int customId;
    private List<String> photourl = new ArrayList<>();

    @Override
    protected void init() {
        new CommonTitle.Builder(this).setTitle("身份信息").build().show();
        customId = getIntent().getIntExtra(IntentConstant.CUSTOM_ID, 0);
        HashMap<String, Object> map = HttpParamMap.getParamMap();
        map.put("customId", customId);
        mPresenter.getRealName(map);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_real_name_info;
    }

    @Override
    protected RealNamePresenter createPresenter() {
        return new RealNamePresenter();
    }

    @Override
    public void onSubmitAuthSuccess() {

    }

    @Override
    public void onGetAuthSuccess(RealNameBean data) {
        if (mIsLive && data != null) {
            photourl.add(data.getUrl_FontIDcard());
            photourl.add(data.getUrl_BackIDcard());
            realNameName.setText(data.getCustom_Name());
            realNameNumber.setText(data.getIDcard_Num().substring(0, 1) + "****************" +
                    data.getIDcard_Num().substring(data.getIDcard_Num().length() - 1, data.getIDcard_Num().length()));
            GlideApp.with(this).load(data.getUrl_FontIDcard()).into(ivFont);
            GlideApp.with(this).load(data.getUrl_BackIDcard()).into(ivBack);
        }
    }

    @Override
    public void onUploadAuthSuccess(UploadFileBean data) {

    }


    @OnClick({R.id.iv_font, R.id.iv_back})
    public void onViewClicked(View view) {
        int position = 0;
        switch (view.getId()) {
            case R.id.iv_font:
                position = 0;
                break;
            case R.id.iv_back:
                position = 1;
                break;
            default:
                break;
        }
        PhotoViewerBean pvb = new PhotoViewerBean(photourl,position) ;
        startActivity(new Intent(this, PhotoViewerActivity.class)
                .putExtra(PhotoViewerActivity.PHOTO_VIEWER_TAG, pvb));
    }
}
